package com.chapter11;

enum Season2{

    SPRING("春天","温暖的"),SUMMER("夏天","炎热的"),AUTUMN("秋天","凉爽的"),WINTER("冬天","寒冷的");

    private String name;
    private String effect;

    private Season2(String name,String effect){
        this.name = name;
        this.effect = effect;
    }

    public String toString(){
        return name+ "是" + effect;
    }
}

public class enum_method {
    public static void main(String[] args) {

        Season2 season = Season2.SPRING;
        Season2 season2 = Season2.SPRING;

        System.out.println("==");
        System.out.println(season == season2);  //true，底层返回name
        System.out.println();

        System.out.println("equals");
        System.out.println(season.equals(season2));//true,底层等价于==
        System.out.println();

        System.out.println("toString,name");
        System.out.println(season.toString());  //底层返回name,但是重写了此方法
        System.out.println(season.name());//两者一样
        System.out.println();

        System.out.println("hashCode");
        System.out.println(season2.hashCode());
        System.out.println(season.hashCode()); //两者一样
        System.out.println();

        System.out.println("ordinal,返回枚举对象初创时的位置");
        System.out.println();

        System.out.println("values(),循环遍历Seanson2数组元素(枚举对象)");
        Season2[] seasons = Season2.values();
        for(Season2 s:seasons){
            System.out.println(s);
        }
        System.out.println();

        System.out.println("valueOf,返回已有常量名SPRING的枚举对象");
        Season2 value = Season2.valueOf("SPRING");
        System.out.println(value);
        System.out.println();

        System.out.println("getDeclaringClass,返回对象的枚举类");
        System.out.println(season.getDeclaringClass());
        System.out.println(season2.getDeclaringClass());
        System.out.println(season.getDeclaringClass() ==
                season2.getDeclaringClass());
        System.out.println();
        //两个枚举对象所对应的枚举常量一样，返回true

        System.out.println("compareTo,比较枚举对象的编号,并返回其差值");
        System.out.println(season.compareTo(season2));
        




    }
}
